package com.farmer.service.impl;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.farmer.mapper.MenuMapper;
import com.farmer.pojo.Menu;
import com.farmer.pojo.MenuAllocation;
import com.farmer.service.MenuService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 86183
 * @description 针对表【menu】的数据库操作Service实现
 * @createDate 2024-04-23 20:28:45
 */
@Service
public class MenuServiceImpl extends ServiceImpl<MenuMapper, Menu> implements MenuService {


    @Override
    public void menuAllocation(MenuAllocation menuAllocation) {
        this.baseMapper.deleteRoleMenus(menuAllocation.getRoleId());
        if (CollUtil.isNotEmpty(menuAllocation.getMenuIds())) {
            this.baseMapper.insertRoleMenus(menuAllocation.getRoleId(), menuAllocation.getMenuIds());
        }
    }

    @Override
    public List<Menu> getUserMenus(Long userId) {
        return this.baseMapper.selectMenuListByUserId(userId);
    }

    @Override
    public void deleteMenuRoles(Integer menuId) {
        this.baseMapper.deleteMenuRoles(menuId);
    }
}




